package managesystem.manager;

import managesystem.JDBCUtils;
import managesystem.help.*;
import managesystem.item.Item;
import managesystem.login.Login;
import managesystem.poverty.Poverty;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

/**
 * @author The setting sun
 * @version 1.0
 * @title: ManagerUI
 * @description: TODO
 * @date 2021/12/8 15:01
 */
public class ManagerUI {
    JFrame frame = new JFrame("管理员");

    JMenuBar menu = new JMenuBar();

    JMenu user = new JMenu("用户");
    JMenuItem returnLogin = new JMenuItem("返回登录界面");

    JMenu ope = new JMenu("功能");

    JMenu show = new JMenu("查询");
    JMenuItem lookMe = new JMenuItem("个人信息");
    JMenuItem showHelpPoverty = new JMenuItem("此帮扶人员下的贫困人员");
    JMenuItem showItemPoverty = new JMenuItem("此项目下的贫困人员");
    JMenuItem showPoverty = new JMenuItem("贫困人员");
    JMenuItem showHelp = new JMenuItem("帮扶人员");
    JMenuItem showItem = new JMenuItem("贫困项目");

    JMenu update = new JMenu("修改");
    JMenuItem updateUserInfo = new JMenuItem("个人信息");
    JMenuItem updatePoverty = new JMenuItem("贫困人员");
    JMenuItem updateHelp = new JMenuItem("帮扶人员");
    JMenuItem updateItem = new JMenuItem("贫困项目");

    JMenu add = new JMenu("添加");
    JMenuItem addPoverty = new JMenuItem("贫困人员");
    JMenuItem addHelp = new JMenuItem("帮扶人员");
    JMenuItem addItem = new JMenuItem("贫困项目");

    JMenu delete = new JMenu("删除");
    JMenuItem deletePoverty = new JMenuItem("贫困人员");
    JMenuItem deleteHelp = new JMenuItem("帮扶人员");
    JMenuItem deleteItem = new JMenuItem("贫困项目");

    JTabbedPane tabbed = new JTabbedPane();

    DefaultTableModel dtmPoverty = new DefaultTableModel();
    JTable povertyTable = new JTable(dtmPoverty);
    JScrollPane povertyScroll = new JScrollPane(povertyTable);

    DefaultTableModel dtmHelp = new DefaultTableModel();
    JTable helpTable = new JTable(dtmHelp);
    JScrollPane helpScroll = new JScrollPane(helpTable);

    DefaultTableModel dtmItem = new DefaultTableModel();
    JTable itemTable = new JTable(dtmItem);
    JScrollPane itemScroll = new JScrollPane(itemTable);

    DefaultTableModel dtm = new DefaultTableModel();
    JTable table = new JTable(dtm);
    JScrollPane scroll = new JScrollPane(table);
    JTableHeader head = table.getTableHeader();

//    public static void main(String[] args) {
//        new ManagerUI().init();
//    }

    public void init() {
        showPovertyInfo();
        showHelpInfo();
        showItemInfo();
        listen();

        user.setFont(new Font("微软雅黑", Font.BOLD, 18));
        returnLogin.setFont(new Font("微软雅黑", Font.BOLD, 14));

        user.setForeground(new Color(0xE74C0B));
        returnLogin.setForeground(new Color(0xE74C0B));

        ope.setFont(new Font("微软雅黑", Font.BOLD, 18));
        show.setFont(new Font("微软雅黑", Font.BOLD, 15));
        lookMe.setFont(new Font("微软雅黑", Font.BOLD, 14));
        showHelpPoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        showItemPoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        showPoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        showHelp.setFont(new Font("微软雅黑", Font.BOLD, 14));
        showItem.setFont(new Font("微软雅黑", Font.BOLD, 14));
        update.setFont(new Font("微软雅黑", Font.BOLD, 15));
        updateUserInfo.setFont(new Font("微软雅黑", Font.BOLD, 14));
        updatePoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        updateHelp.setFont(new Font("微软雅黑", Font.BOLD, 14));
        updateItem.setFont(new Font("微软雅黑", Font.BOLD, 14));
        add.setFont(new Font("微软雅黑", Font.BOLD, 15));
        addPoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        addHelp.setFont(new Font("微软雅黑", Font.BOLD, 14));
        addItem.setFont(new Font("微软雅黑", Font.BOLD, 14));
        delete.setFont(new Font("微软雅黑", Font.BOLD, 15));
        deletePoverty.setFont(new Font("微软雅黑", Font.BOLD, 14));
        deleteHelp.setFont(new Font("微软雅黑", Font.BOLD, 14));
        deleteItem.setFont(new Font("微软雅黑", Font.BOLD, 14));

        ope.setForeground(new Color(0xE74C0B));
        show.setForeground(new Color(0xE74C0B));
        lookMe.setForeground(new Color(0xE74C0B));
        showHelpPoverty.setForeground(new Color(0xE74C0B));
        showItemPoverty.setForeground(new Color(0xE74C0B));
        showPoverty.setForeground(new Color(0xE74C0B));
        showHelp.setForeground(new Color(0xE74C0B));
        showItem.setForeground(new Color(0xE74C0B));
        update.setForeground(new Color(0xE74C0B));
        updateUserInfo.setForeground(new Color(0xE74C0B));
        updatePoverty.setForeground(new Color(0xE74C0B));
        updateHelp.setForeground(new Color(0xE74C0B));
        updateItem.setForeground(new Color(0xE74C0B));
        add.setForeground(new Color(0xE74C0B));
        addPoverty.setForeground(new Color(0xE74C0B));
        addHelp.setForeground(new Color(0xE74C0B));
        addItem.setForeground(new Color(0xE74C0B));
        delete.setForeground(new Color(0xE74C0B));
        deletePoverty.setForeground(new Color(0xE74C0B));
        deleteHelp.setForeground(new Color(0xE74C0B));
        deleteItem.setForeground(new Color(0xE74C0B));

        JTableHeader povertyHead = povertyTable.getTableHeader();
        povertyHead.setFont(new Font("微软雅黑", 1, 15));
        povertyHead.setReorderingAllowed(false);

        povertyTable.setFont(new Font("微软雅黑", 1, 13));
        povertyTable.setEnabled(false);
        povertyTable.setRowHeight(20);

        JTableHeader helpHead = helpTable.getTableHeader();
        helpHead.setFont(new Font("微软雅黑", 1, 15));
        helpHead.setReorderingAllowed(false);

        helpTable.setFont(new Font("微软雅黑", 1, 13));
        helpTable.setEnabled(false);
        helpTable.setRowHeight(20);

        JTableHeader itemHead = itemTable.getTableHeader();
        itemHead.setFont(new Font("微软雅黑", 1, 15));
        itemHead.setReorderingAllowed(false);

        itemTable.setFont(new Font("微软雅黑", 1, 13));
        itemTable.setEnabled(false);
        itemTable.setRowHeight(20);

        user.add(updateUserInfo);
        user.add(returnLogin);

        ope.add(show);
        ope.add(update);
        ope.add(add);
        ope.add(delete);

        show.add(lookMe);
        show.add(showHelpPoverty);
        show.add(showItemPoverty);
        show.add(showPoverty);
        show.add(showHelp);
        show.add(showItem);

        update.add(updateUserInfo);
        update.add(updatePoverty);
        update.add(updateHelp);
        update.add(updateItem);

        add.add(addPoverty);
        add.add(addHelp);
        add.add(addItem);

        delete.add(deletePoverty);
        delete.add(deleteHelp);
        delete.add(deleteItem);

        menu.add(user);
        menu.add(ope);

        tabbed.add("贫困人员信息", povertyScroll);
        tabbed.add("帮扶人员信息", helpScroll);
        tabbed.add("贫困项目信息", itemScroll);

        frame.setJMenuBar(menu);
        frame.add(tabbed);

        frame.setVisible(true);
        frame.setSize(1200, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    public void listen() {
        returnLogin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
                new Login().init();
            }
        });

        lookMe.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String lookMe = "select * from user_root";
                Manager mng = JDBCUtils.getManagerInfo(lookMe);

                PublicTableShowInfo dialog = new PublicTableShowInfo();
                dialog.setSize(500, 150);
                dialog.init();

                dtm.getDataVector().removeAllElements();

                String[] title = new String[]{"管理员编号", "姓名", "年龄", "性别", "民族"};
                dtm.setColumnIdentifiers(title);

                dtm.addRow(new Object[]{mng.getRid(), mng.getRname(), mng.getRage(),
                        mng.getRsex(), mng.getRnation()});
            }
        });

        showHelpPoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new showHelpPovertyDialog().init();
            }
        });

        showItemPoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new showItemPovertyDialog().init();
            }
        });

        showPoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ShowPovertyDialog().init();
            }
        });

        showHelp.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ShowHelpDialog().init();
            }
        });

        showItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new ShowItemDialog().init();
            }
        });

        updateUserInfo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdateUserInfoDialog().init();
            }
        });

        updatePoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdatePovertyGetPidDialog().init();
            }
        });

        updateHelp.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdateHelpGetHidDialog().init();
            }
        });

        updateItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new UpdateItemGetIidDialog().init();
            }
        });

        addPoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addPovertyDialog().init();
            }
        });

        addHelp.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addHelpDialog().init();
            }
        });

        addItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new addItemDialog().init();
            }
        });

        deletePoverty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new DeletePovertyDialog().init();
            }
        });

        deleteHelp.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new DeleteHelpDialog().init();
            }
        });

        deleteItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new DeleteItemDialog().init();
            }
        });
    }

    public void showPovertyInfo() {
        String sql = "select * from user_poor";
        ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sql);

        String[] title = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
        dtmPoverty.setColumnIdentifiers(title);

        for (int i = 0; i < list.size(); i++) {
            dtmPoverty.addRow(new Object[]{list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                    list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                    list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
        }
    }

    public void showHelpInfo() {
        String sql = "select * from user_helper";
        ArrayList<Help> list = JDBCUtils.getHelpAllInfo(sql);

        String[] title = new String[]{"帮扶人员编号", "姓名", "年龄", "性别", "民族", "地址"};
        dtmHelp.setColumnIdentifiers(title);

        for (int i = 0; i < list.size(); i++) {
            dtmHelp.addRow(new Object[]{list.get(i).getHid(), list.get(i).getHname(), list.get(i).getHage(),
                    list.get(i).getHsex(), list.get(i).getHnation(), list.get(i).getAddress()});
        }
    }

    public void showItemInfo() {
        String sql = "select * from items";
        ArrayList<Item> list = JDBCUtils.getItemAllInfo(sql);

        String[] title = new String[]{"项目编号", "项目名称", "项目类型"};
        dtmItem.setColumnIdentifiers(title);

        for (int i = 0; i < list.size(); i++) {
            dtmItem.addRow(new Object[]{list.get(i).getIid(), list.get(i).getIname(), list.get(i).getIclass()});
        }
    }

    class showHelpPovertyDialog extends JDialog {
        JLabel hidLabel = new JLabel("请输入你要查询的贫困人员编号：");
        JTextField hidText = new JTextField(10);
        JButton hidButton = new JButton("确定");

        public void init() {
            listen();

            hidLabel.setFont(new Font("微软雅黑", 1, 16));
            hidText.setFont(new Font("微软雅黑", 1, 14));
            hidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(hidLabel);
            add(hidText);
            add(hidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getHelp = "select * from user_helper";
            ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

            hidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean HelpIs = false;
                    for (int i = 0; i < helpList.size(); i++) {
                        if (String.valueOf(helpList.get(i).getHid()).equals(hidText.getText())) {
                            HelpIs = true;
                        }
                    }

                    if (HelpIs == false) {
                        new ItemNotExistHint().init();
                    } else {
                        dispose();

                        PublicTableShowInfo dialog = new PublicTableShowInfo();
                        dialog.setSize(1500, 300);
                        dialog.init();

                        dtm.getDataVector().removeAllElements();

                        String sqlHelp = "select * from user_helper where hid = ?";
                        Help help = JDBCUtils.getHelpOneInfo(sqlHelp, hidText.getText());

                        String sqlPoverty = "select * from user_poor where iid = ?";
                        ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sqlPoverty, hidText.getText());

                        String[] title = new String[]{"贫困人员编号", "贫困人员姓名",
                                "贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                        dtm.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtm.addRow(new Object[]{help.getHid(), help.getHname(),
                                    list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                                    list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                                    list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
                        }
                    }
                }
            });
        }
    }

    class showItemPovertyDialog extends JDialog {
        JLabel iidLabel = new JLabel("请输入你要查询的贫困项目编号：");
        JTextField iidText = new JTextField(10);
        JButton iidButton = new JButton("确定");

        public void init() {
            listen();

            iidLabel.setFont(new Font("微软雅黑", 1, 16));
            iidText.setFont(new Font("微软雅黑", 1, 14));
            iidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(iidLabel);
            add(iidText);
            add(iidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getItem = "select * from items";
            ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

            iidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean itemIs = false;
                    for (int i = 0; i < itemList.size(); i++) {
                        if (String.valueOf(itemList.get(i).getIid()).equals(iidText.getText())) {
                            itemIs = true;
                        }
                    }

                    if (itemIs == false) {
                        new ItemNotExistHint().init();
                    } else {
                        dispose();

                        PublicTableShowInfo dialog = new PublicTableShowInfo();
                        dialog.setSize(1500, 300);
                        dialog.init();

                        dtm.getDataVector().removeAllElements();

                        String sqlItem = "select * from items";
                        Item item = JDBCUtils.getItemOneInfo(sqlItem);

                        String sqlPoverty = "select * from user_poor where iid = ?";
                        ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sqlPoverty, iidText.getText());

                        String[] title = new String[]{"项目编号", "项目名称", "项目类型",
                                "贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                        dtm.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtm.addRow(new Object[]{item.getIid(), item.getIname(), item.getIclass(),
                                    list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                                    list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                                    list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
                        }
                    }
                }
            });
        }
    }

    class ShowPovertyDialog extends JDialog {
        JLabel pidLabel = new JLabel("请输入你要查询的贫困人员编号：");
        JTextField pidText = new JTextField(10);
        JButton pidButton = new JButton("确定");

        public void init() {
            listen();

            pidLabel.setFont(new Font("微软雅黑", 1, 16));
            pidText.setFont(new Font("微软雅黑", 1, 14));
            pidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(pidLabel);
            add(pidText);
            add(pidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getPoverty = "select * from user_poor";
            ArrayList<Poverty> povertyList = JDBCUtils.getPovertyAllInfo(getPoverty);

            pidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < povertyList.size(); i++) {
                        if (String.valueOf(povertyList.get(i).getPid()).equals(pidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new PovertyNotExistHint().init();
                    } else {
                        dispose();

                        PublicTableShowInfo dialog = new PublicTableShowInfo();
                        dialog.setSize(1200, 150);
                        dialog.init();

                        dtm.getDataVector().removeAllElements();

                        Integer pid = new Integer(pidText.getText());
                        String sql = "select * from user_poor where pid = ?";
                        Poverty poverty = JDBCUtils.getPovertyOneInfo(sql, pid);

                        if (poverty.getHid() == null && poverty.getIid() == null) {
                            new PovertyHidIidIsNULLHint().init();
                        } else if (poverty.getHid() == null) {
                            new PovertyHidIsNULLHint().init();
                        } else if (poverty.getIid() == null) {
                            new PovertyIidIsNULLHint().init();
                        }

                        String[] title = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                        dtm.setColumnIdentifiers(title);

                        dtm.addRow(new Object[]{poverty.getPid(), poverty.getHid(), poverty.getIid(), poverty.getPname(),
                                poverty.getPage(), poverty.getPsex(), poverty.getPnation(), poverty.getBirthplace(),
                                poverty.getReason(), poverty.getHealth(), poverty.getEducated(), poverty.getDate()});
                    }
                }
            });
        }
    }

    class ShowHelpDialog extends JDialog {
        JLabel hidLabel = new JLabel("请输入你要查询的帮扶人员编号：");
        JTextField hidText = new JTextField(10);
        JButton hidButton = new JButton("确定");

        public void init() {
            listen();

            hidLabel.setFont(new Font("微软雅黑", 1, 16));
            hidText.setFont(new Font("微软雅黑", 1, 14));
            hidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(hidLabel);
            add(hidText);
            add(hidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getHelp = "select * from user_helper";
            ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

            hidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean HelpIs = false;
                    for (int i = 0; i < helpList.size(); i++) {
                        if (String.valueOf(helpList.get(i).getHid()).equals(hidText.getText())) {
                            HelpIs = true;
                        }
                    }

                    if (HelpIs == false) {
                        new HelpNotExistHint().init();
                    } else {
                        dispose();

                        PublicTableShowInfo dialog = new PublicTableShowInfo();
                        dialog.setSize(600, 150);
                        dialog.init();

                        dtm.getDataVector().removeAllElements();

                        Integer hid = new Integer(hidText.getText());
                        String sql = "select * from user_helper where hid = ?";
                        Help help = JDBCUtils.getHelpOneInfo(sql, hid);

                        String[] title = new String[]{"帮扶人员编号", "姓名", "年龄", "性别", "民族", "地址"};
                        dtm.setColumnIdentifiers(title);

                        dtm.addRow(new Object[]{help.getHid(), help.getHname(), help.getHage(),
                                help.getHsex(), help.getHnation(), help.getAddress()});
                    }
                }
            });
        }
    }

    class ShowItemDialog extends JDialog {
        JLabel iidLabel = new JLabel("请输入你要查询的贫困项目编号：");
        JTextField iidText = new JTextField(10);
        JButton iidButton = new JButton("确定");

        public void init() {
            listen();

            iidLabel.setFont(new Font("微软雅黑", 1, 16));
            iidText.setFont(new Font("微软雅黑", 1, 14));
            iidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(iidLabel);
            add(iidText);
            add(iidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getItem = "select * from items";
            ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

            iidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < itemList.size(); i++) {
                        if (String.valueOf(itemList.get(i).getIid()).equals(iidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new ItemNotExistHint().init();
                    } else {
                        dispose();

                        PublicTableShowInfo dialog = new PublicTableShowInfo();
                        dialog.setSize(500, 150);
                        dialog.init();

                        dtm.getDataVector().removeAllElements();

                        Integer iid = new Integer(iidText.getText());
                        String sql = "select * from items where iid = ?";
                        Item item = JDBCUtils.getItemOneInfo(sql, iid);

                        String[] title = new String[]{"项目编号", "项目名称", "项目类型"};
                        dtm.setColumnIdentifiers(title);

                        dtm.addRow(new Object[]{item.getIid(), item.getIname(), item.getIclass()});
                    }
                }
            });
        }
    }

    class UpdateUserInfoDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(4, 1, 35, 35));
        JPanel p2 = new JPanel(new GridLayout(4, 1, 35, 35));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("修改个人信息");

        JLabel name = new JLabel("姓名：");
        JLabel age = new JLabel("年龄：");
        JLabel sex = new JLabel("性别：");
        JLabel nation = new JLabel("民族：");

        JTextField nameText = new JTextField(16);
        JTextField ageText = new JTextField(16);
        JTextField sexText = new JTextField(16);
        JTextField nationText = new JTextField(16);

        JButton updateButton = new JButton("修改");

        public void init() {
            listen();

            String sql = "select * from user_root";
            Manager mng = JDBCUtils.getManagerInfo(sql);

            title.setFont(new Font("楷体", Font.BOLD, 30));

            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            age.setFont(new Font("微软雅黑", Font.BOLD, 16));
            sex.setFont(new Font("微软雅黑", Font.BOLD, 16));
            nation.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            ageText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            sexText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nationText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            updateButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setText(mng.getRname());
            ageText.setText(String.valueOf(mng.getRage()));
            sexText.setText(mng.getRsex());
            nationText.setText(mng.getRnation());

            p.add(title);

            p1.add(name);
            p1.add(age);
            p1.add(sex);
            p1.add(nation);

            p2.add(nameText);
            p2.add(ageText);
            p2.add(sexText);
            p2.add(nationText);

            p3.add(updateButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(300, 350);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            updateButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!nameText.getText().equals("") && !ageText.getText().equals("") &&
                            !sexText.getText().equals("") && !nationText.getText().equals("")) {
                        String update = "update user_root set rname = ?, rage = ?, rsex = ?, rnation = ?";
                        JDBCUtils.UpdateHelpInfo(update, nameText.getText(), ageText.getText(), sexText.getText(),
                                nationText.getText());

                        dispose();
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (ageText.getText().equals("")) {
                        ageText.setForeground(Color.RED);
                        ageText.setText("此框不能为空！");
                    }

                    if (sexText.getText().equals("")) {
                        sexText.setForeground(Color.RED);
                        sexText.setText("此框不能为空！");
                    }

                    if (nationText.getText().equals("")) {
                        nationText.setForeground(Color.RED);
                        nationText.setText("此框不能为空！");
                    }
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            ageText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ageText.setText("");
                    ageText.setForeground(Color.BLACK);
                }
            });

            sexText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    sexText.setText("");
                    sexText.setForeground(Color.BLACK);
                }
            });

            nationText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nationText.setText("");
                    nationText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class UpdatePovertyGetPidDialog extends JDialog {
        JLabel pidLabel = new JLabel("请输入你要修改的贫困人员编号：");
        JTextField pidText = new JTextField(10);
        JButton pidButton = new JButton("确定");

        public void init() {
            listen();

            pidLabel.setFont(new Font("微软雅黑", 1, 16));
            pidText.setFont(new Font("微软雅黑", 1, 14));
            pidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(pidLabel);
            add(pidText);
            add(pidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getPoverty = "select * from user_poor";
            ArrayList<Poverty> povertyList = JDBCUtils.getPovertyAllInfo(getPoverty);

            pidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < povertyList.size(); i++) {
                        if (String.valueOf(povertyList.get(i).getPid()).equals(pidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new PovertyNotExistHint().init();
                    } else {
                        new UpdatePovertyDialog(Integer.valueOf(pidText.getText())).init();

                        dispose();
                    }
                }
            });
        }
    }

    class UpdatePovertyDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(11, 1, 20, 20));
        JPanel p2 = new JPanel(new GridLayout(11, 1, 20, 20));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("修改信息");

        JLabel help = new JLabel("帮扶人员编号：");
        JLabel item = new JLabel("项目编号：");
        JLabel name = new JLabel("姓名：");
        JLabel age = new JLabel("年龄：");
        JLabel sex = new JLabel("性别：");
        JLabel nation = new JLabel("民族：");
        JLabel birthplace = new JLabel("籍贯：");
        JLabel reason = new JLabel("贫困原因：");
        JLabel health = new JLabel("身体状况：");
        JLabel educated = new JLabel("受教育程度：");
        JLabel date = new JLabel("登记时间：");

        JTextField helpText = new JTextField(16);
        JTextField itemText = new JTextField(16);
        JTextField nameText = new JTextField(16);
        JTextField ageText = new JTextField(16);
        JTextField sexText = new JTextField(16);
        JTextField nationText = new JTextField(16);
        JTextField birthplaceText = new JTextField(16);
        JTextField reasonText = new JTextField(16);
        JTextField healthText = new JTextField(16);
        JTextField educatedText = new JTextField(16);
        JTextField dateText = new JTextField(16);

        JButton updateButton = new JButton("修改");

        Integer povertyId;

        public UpdatePovertyDialog(Integer povertyId) {
            this.povertyId = povertyId;
        }

        public void init() {
            listen();

            String sql = "select * from user_poor where pid = ?";
            Poverty poverty = JDBCUtils.getPovertyOneInfo(sql, povertyId);

            title.setFont(new Font("楷体", Font.BOLD, 40));

            help.setFont(new Font("微软雅黑", Font.BOLD, 16));
            item.setFont(new Font("微软雅黑", Font.BOLD, 16));
            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            age.setFont(new Font("微软雅黑", Font.BOLD, 16));
            sex.setFont(new Font("微软雅黑", Font.BOLD, 16));
            nation.setFont(new Font("微软雅黑", Font.BOLD, 16));
            birthplace.setFont(new Font("微软雅黑", Font.BOLD, 16));
            reason.setFont(new Font("微软雅黑", Font.BOLD, 16));
            health.setFont(new Font("微软雅黑", Font.BOLD, 16));
            educated.setFont(new Font("微软雅黑", Font.BOLD, 16));
            date.setFont(new Font("微软雅黑", Font.BOLD, 16));

            helpText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            itemText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            ageText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            sexText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nationText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            birthplaceText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            reasonText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            healthText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            educatedText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            dateText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            updateButton.setFont(new Font("微软雅黑", Font.BOLD, 20));

            helpText.setText(String.valueOf(poverty.getHid()));
            itemText.setText(String.valueOf(poverty.getIid()));
            nameText.setText(poverty.getPname());
            ageText.setText(String.valueOf(poverty.getPage()));
            sexText.setText(poverty.getPsex());
            nationText.setText(poverty.getPnation());
            birthplaceText.setText(poverty.getBirthplace());
            reasonText.setText(poverty.getReason());
            healthText.setText(poverty.getHealth());
            educatedText.setText(poverty.getEducated());
            dateText.setText(poverty.getDate());

            p.add(title);

            p1.add(help);
            p1.add(item);
            p1.add(name);
            p1.add(age);
            p1.add(sex);
            p1.add(nation);
            p1.add(birthplace);
            p1.add(reason);
            p1.add(health);
            p1.add(educated);
            p1.add(date);

            p2.add(helpText);
            p2.add(itemText);
            p2.add(nameText);
            p2.add(ageText);
            p2.add(sexText);
            p2.add(nationText);
            p2.add(birthplaceText);
            p2.add(reasonText);
            p2.add(healthText);
            p2.add(educatedText);
            p2.add(dateText);

            p3.add(updateButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(500, 700);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            updateButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String getHelp = "select * from user_helper";
                    ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

                    String getItem = "select * from items";
                    ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

                    Boolean helpIs = false;
                    Boolean itemIs = false;
                    Boolean helpIsNULL = false;
                    Boolean itemIsNULL = false;

                    for (int i = 0; i < helpList.size(); i++) {
                        if (String.valueOf(helpList.get(i).getHid()).equals(helpText.getText())) {
                            helpIs = true;
                        }
                    }

                    for (int i = 0; i < itemList.size(); i++) {
                        if (String.valueOf(itemList.get(i).getIid()).equals(itemText.getText())) {
                            itemIs = true;
                        }
                    }

                    if (!"null".equals(helpText.getText())) {
                        helpIsNULL = true;
                    } else {
                        helpText.setForeground(Color.RED);
                        helpText.setText("帮扶人员编号有误！");
                    }

                    if (!"null".equals(itemText.getText())) {
                        itemIsNULL = true;
                    } else {
                        itemText.setForeground(Color.RED);
                        itemText.setText("贫困项目编号有误！");
                    }


                    if (helpIs == false) {
                        helpText.setForeground(Color.RED);
                        helpText.setText("帮扶人员编号有误！");
                    }

                    if (itemIs == false) {
                        itemText.setForeground(Color.RED);
                        itemText.setText("贫困项目编号有误！");
                    }

                    if (!helpText.getText().equals("") && !itemText.getText().equals("") &&
                            !nameText.getText().equals("") && !ageText.getText().equals("") &&
                            !sexText.getText().equals("") && !nationText.getText().equals("") &&
                            !birthplaceText.getText().equals("") && !reasonText.getText().equals("") &&
                            !healthText.getText().equals("") && !educatedText.getText().equals("") &&
                            !dateText.getText().equals("")) {
                        if (helpIs && itemIs && helpIsNULL && itemIsNULL) {
                            String update = "update user_poor set hid = ?, iid = ?, pname = ?, page = ?, psex = ?, pnation = ?, birthplace = ?, reason = ?, health = ?, educated = ?, date = ? where pid = ?";
                            JDBCUtils.UpdatePovertyInfo(update, helpText.getText(), itemText.getText(), nameText.getText(),
                                    ageText.getText(), sexText.getText(), nationText.getText(), birthplaceText.getText(),
                                    reasonText.getText(), healthText.getText(), educatedText.getText(), dateText.getText(), povertyId);

                            String sql = "select * from user_poor";
                            ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sql);

                            dtmPoverty.getDataVector().removeAllElements();

                            String[] title = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                            dtmPoverty.setColumnIdentifiers(title);

                            for (int i = 0; i < list.size(); i++) {
                                dtmPoverty.addRow(new Object[]{list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                                        list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                                        list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
                            }

                            dispose();
                        }
                    }

                    if (helpText.getText().equals("")) {
                        helpText.setForeground(Color.RED);
                        helpText.setText("此框不能为空！");
                    }

                    if (itemText.getText().equals("")) {
                        itemText.setForeground(Color.RED);
                        itemText.setText("此框不能为空！");
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (ageText.getText().equals("")) {
                        ageText.setForeground(Color.RED);
                        ageText.setText("此框不能为空！");
                    }

                    if (sexText.getText().equals("")) {
                        sexText.setForeground(Color.RED);
                        sexText.setText("此框不能为空！");
                    }

                    if (nationText.getText().equals("")) {
                        nationText.setForeground(Color.RED);
                        nationText.setText("此框不能为空！");
                    }

                    if (birthplaceText.getText().equals("")) {
                        birthplaceText.setForeground(Color.RED);
                        birthplaceText.setText("此框不能为空！");
                    }

                    if (reasonText.getText().equals("")) {
                        reasonText.setForeground(Color.RED);
                        reasonText.setText("此框不能为空！");
                    }

                    if (healthText.getText().equals("")) {
                        healthText.setForeground(Color.RED);
                        healthText.setText("此框不能为空！");
                    }

                    if (educatedText.getText().equals("")) {
                        educatedText.setForeground(Color.RED);
                        educatedText.setText("此框不能为空！");
                    }

                    if (dateText.getText().equals("")) {
                        dateText.setForeground(Color.RED);
                        dateText.setText("此框不能为空！");
                    }
                }
            });

            helpText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    helpText.setText("");
                    helpText.setForeground(Color.BLACK);
                }
            });

            itemText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    itemText.setText("");
                    itemText.setForeground(Color.BLACK);
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            ageText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ageText.setText("");
                    ageText.setForeground(Color.BLACK);
                }
            });

            sexText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    sexText.setText("");
                    sexText.setForeground(Color.BLACK);
                }
            });

            nationText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nationText.setText("");
                    nationText.setForeground(Color.BLACK);
                }
            });

            birthplaceText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    birthplaceText.setText("");
                    birthplaceText.setForeground(Color.BLACK);
                }
            });

            reasonText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    reasonText.setText("");
                    reasonText.setForeground(Color.BLACK);
                }
            });

            healthText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    healthText.setText("");
                    healthText.setForeground(Color.BLACK);
                }
            });

            educatedText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    educatedText.setText("");
                    educatedText.setForeground(Color.BLACK);
                }
            });

            dateText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    dateText.setText("");
                    dateText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class UpdateHelpGetHidDialog extends JDialog {
        JLabel hidLabel = new JLabel("请输入你要修改的帮扶人员编号：");
        JTextField hidText = new JTextField(10);
        JButton hidButton = new JButton("确定");

        public void init() {
            listen();

            hidLabel.setFont(new Font("微软雅黑", 1, 16));
            hidText.setFont(new Font("微软雅黑", 1, 14));
            hidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(hidLabel);
            add(hidText);
            add(hidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getHelp = "select * from user_helper";
            ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

            hidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean HelpIs = false;
                    for (int i = 0; i < helpList.size(); i++) {
                        if (String.valueOf(helpList.get(i).getHid()).equals(hidText.getText())) {
                            HelpIs = true;
                        }
                    }

                    if (HelpIs == false) {
                        new HelpNotExistHint().init();
                    } else {
                        new UpdateHelpDialog(Integer.valueOf(hidText.getText())).init();

                        dispose();
                    }
                }
            });
        }
    }

    class UpdateHelpDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(5, 1, 20, 20));
        JPanel p2 = new JPanel(new GridLayout(5, 1, 20, 20));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("修改信息");

        JLabel name = new JLabel("姓名：");
        JLabel age = new JLabel("年龄：");
        JLabel sex = new JLabel("性别：");
        JLabel nation = new JLabel("民族：");
        JLabel address = new JLabel("地址：");

        JTextField nameText = new JTextField(16);
        JTextField ageText = new JTextField(16);
        JTextField sexText = new JTextField(16);
        JTextField nationText = new JTextField(16);
        JTextField addressText = new JTextField(16);

        JButton updateButton = new JButton("修改");

        Integer helpId;

        public UpdateHelpDialog(Integer helpId) {
            this.helpId = helpId;
        }

        public void init() {
            listen();

            String sql = "select * from user_helper where hid = ?";
            Help help = JDBCUtils.getHelpOneInfo(sql, helpId);

            title.setFont(new Font("楷体", Font.BOLD, 30));

            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            age.setFont(new Font("微软雅黑", Font.BOLD, 16));
            sex.setFont(new Font("微软雅黑", Font.BOLD, 16));
            nation.setFont(new Font("微软雅黑", Font.BOLD, 16));
            address.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            ageText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            sexText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nationText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            addressText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            updateButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setText(help.getHname());
            ageText.setText(String.valueOf(help.getHage()));
            sexText.setText(help.getHsex());
            nationText.setText(help.getHnation());
            addressText.setText(help.getAddress());

            p.add(title);

            p1.add(name);
            p1.add(age);
            p1.add(sex);
            p1.add(nation);
            p1.add(address);

            p2.add(nameText);
            p2.add(ageText);
            p2.add(sexText);
            p2.add(nationText);
            p2.add(addressText);

            p3.add(updateButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(300, 350);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            updateButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!nameText.getText().equals("") && !ageText.getText().equals("") &&
                            !sexText.getText().equals("") && !nationText.getText().equals("") &&
                            !addressText.getText().equals("")) {
                        String update = "update user_helper set hname = ?, hage = ?, hsex = ?, hnation = ?, address = ? where hid = ?";
                        JDBCUtils.UpdateHelpInfo(update, nameText.getText(), ageText.getText(), sexText.getText(),
                                nationText.getText(), addressText.getText(), helpId);

                        String sql = "select * from user_helper";
                        ArrayList<Help> list = JDBCUtils.getHelpAllInfo(sql);

                        dtmHelp.getDataVector().removeAllElements();

                        String[] title = new String[]{"帮扶人员编号", "姓名", "年龄", "性别", "民族", "地址"};
                        dtmHelp.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtmHelp.addRow(new Object[]{list.get(i).getHid(), list.get(i).getHname(), list.get(i).getHage(),
                                    list.get(i).getHsex(), list.get(i).getHnation(), list.get(i).getAddress(),});
                        }

                        dispose();
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (ageText.getText().equals("")) {
                        ageText.setForeground(Color.RED);
                        ageText.setText("此框不能为空！");
                    }

                    if (sexText.getText().equals("")) {
                        sexText.setForeground(Color.RED);
                        sexText.setText("此框不能为空！");
                    }

                    if (nationText.getText().equals("")) {
                        nationText.setForeground(Color.RED);
                        nationText.setText("此框不能为空！");
                    }

                    if (addressText.getText().equals("")) {
                        addressText.setForeground(Color.RED);
                        addressText.setText("此框不能为空！");
                    }
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            ageText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ageText.setText("");
                    ageText.setForeground(Color.BLACK);
                }
            });

            sexText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    sexText.setText("");
                    sexText.setForeground(Color.BLACK);
                }
            });

            nationText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nationText.setText("");
                    nationText.setForeground(Color.BLACK);
                }
            });

            addressText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    addressText.setText("");
                    addressText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class UpdateItemGetIidDialog extends JDialog {
        JLabel iidLabel = new JLabel("请输入你要修改的贫困项目编号：");
        JTextField iidText = new JTextField(10);
        JButton iidButton = new JButton("确定");

        public void init() {
            listen();

            iidLabel.setFont(new Font("微软雅黑", 1, 16));
            iidText.setFont(new Font("微软雅黑", 1, 14));
            iidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(iidLabel);
            add(iidText);
            add(iidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getItem = "select * from items";
            ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

            iidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean HelpIs = false;
                    for (int i = 0; i < itemList.size(); i++) {
                        if (String.valueOf(itemList.get(i).getIid()).equals(iidText.getText())) {
                            HelpIs = true;
                        }
                    }

                    if (HelpIs == false) {
                        new ItemNotExistHint().init();
                    } else {
                        new UpdateItemDialog(Integer.valueOf(iidText.getText())).init();

                        dispose();
                    }
                }
            });
        }
    }

    class UpdateItemDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(2, 1, 25, 25));
        JPanel p2 = new JPanel(new GridLayout(2, 1, 25, 25));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("修改项目信息");

        JLabel name = new JLabel("项目名称：");
        JLabel iClass = new JLabel("项目类型：");

        JTextField nameText = new JTextField(16);
        JTextField iClassText = new JTextField(16);

        JButton updateButton = new JButton("修改");

        Integer itemId;

        public UpdateItemDialog(Integer itemId) {
            this.itemId = itemId;
        }

        public void init() {
            listen();

            String sql = "select * from items where iid = ?";
            Item item = JDBCUtils.getItemOneInfo(sql, itemId);

            title.setFont(new Font("楷体", Font.BOLD, 30));

            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            iClass.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            iClassText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            updateButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setText(item.getIname());
            iClassText.setText(item.getIclass());

            p.add(title);

            p1.add(name);
            p1.add(iClass);

            p2.add(nameText);
            p2.add(iClassText);

            p3.add(updateButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(300, 220);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            updateButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!nameText.getText().equals("") && !iClassText.getText().equals("") ) {
                        String update = "update items set iname = ?, iclass = ? where iid = ?";
                        JDBCUtils.UpdateHelpInfo(update, nameText.getText(), iClassText.getText(), itemId);

                        String sql = "select * from items";
                        ArrayList<Item> list = JDBCUtils.getItemAllInfo(sql);

                        dtmItem.getDataVector().removeAllElements();

                        String[] title = new String[]{"项目编号", "项目名称", "项目类型"};
                        dtmItem.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtmItem.addRow(new Object[]{list.get(i).getIid(), list.get(i).getIname(), list.get(i).getIclass()});
                        }

                        dispose();
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (iClassText.getText().equals("")) {
                        iClassText.setForeground(Color.RED);
                        iClassText.setText("此框不能为空！");
                    }
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            iClassText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    iClassText.setText("");
                    iClassText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class addPovertyDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(11, 1, 25, 25));
        JPanel p2 = new JPanel(new GridLayout(11, 1, 25, 25));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("填写信息");

        JLabel help = new JLabel("帮扶人员编号：");
        JLabel item = new JLabel("项目编号：");
        JLabel name = new JLabel("姓名：");
        JLabel age = new JLabel("年龄：");
        JLabel sex = new JLabel("性别：");
        JLabel nation = new JLabel("民族：");
        JLabel birthplace = new JLabel("籍贯：");
        JLabel reason = new JLabel("贫困原因：");
        JLabel health = new JLabel("身体状况：");
        JLabel educated = new JLabel("受教育程度：");
        JLabel date = new JLabel("登记时间：");

        JTextField helpText = new JTextField(16);
        JTextField itemText = new JTextField(16);
        JTextField nameText = new JTextField(16);
        JTextField ageText = new JTextField(16);
        JTextField sexText = new JTextField(16);
        JTextField nationText = new JTextField(16);
        JTextField birthplaceText = new JTextField(16);
        JTextField reasonText = new JTextField(16);
        JTextField healthText = new JTextField(16);
        JTextField educatedText = new JTextField(16);
        JTextField dateText = new JTextField(16);

        JButton addButton = new JButton("添加");

        public void init() {
            listen();

            title.setFont(new Font("楷体", Font.BOLD, 40));

            help.setFont(new Font("微软雅黑", Font.BOLD, 16));
            item.setFont(new Font("微软雅黑", Font.BOLD, 16));
            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            age.setFont(new Font("微软雅黑", Font.BOLD, 16));
            sex.setFont(new Font("微软雅黑", Font.BOLD, 16));
            nation.setFont(new Font("微软雅黑", Font.BOLD, 16));
            birthplace.setFont(new Font("微软雅黑", Font.BOLD, 16));
            reason.setFont(new Font("微软雅黑", Font.BOLD, 16));
            health.setFont(new Font("微软雅黑", Font.BOLD, 16));
            educated.setFont(new Font("微软雅黑", Font.BOLD, 16));
            date.setFont(new Font("微软雅黑", Font.BOLD, 16));

            helpText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            itemText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            ageText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            sexText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nationText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            birthplaceText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            reasonText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            healthText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            educatedText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            dateText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            addButton.setFont(new Font("微软雅黑", Font.BOLD, 20));

            dateText.setText("格式为：YYYY-MM-DD");

            p.add(title);

            p1.add(help);
            p1.add(item);
            p1.add(name);
            p1.add(age);
            p1.add(sex);
            p1.add(nation);
            p1.add(birthplace);
            p1.add(reason);
            p1.add(health);
            p1.add(educated);
            p1.add(date);

            p2.add(helpText);
            p2.add(itemText);
            p2.add(nameText);
            p2.add(ageText);
            p2.add(sexText);
            p2.add(nationText);
            p2.add(birthplaceText);
            p2.add(reasonText);
            p2.add(healthText);
            p2.add(educatedText);
            p2.add(dateText);

            p3.add(addButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(450, 700);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            addButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String getHelp = "select * from user_helper";
                    ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

                    String getItem = "select * from items";
                    ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

                    Boolean helpIs = false;
                    Boolean itemIs = false;

                    if (!helpText.getText().equals("") && !itemText.getText().equals("") &&
                            !nameText.getText().equals("") && !ageText.getText().equals("") &&
                            !sexText.getText().equals("") && !nationText.getText().equals("") &&
                            !birthplaceText.getText().equals("") && !reasonText.getText().equals("") &&
                            !healthText.getText().equals("") && !educatedText.getText().equals("") &&
                            !dateText.getText().equals("") && !dateText.getText().equals("格式为：YYYY-MM-DD")) {

                        for (int i = 0; i < helpList.size(); i++) {
                            if (String.valueOf(helpList.get(i).getHid()).equals(helpText.getText())) {
                                helpIs = true;
                            }
                        }

                        for (int i = 0; i < itemList.size(); i++) {
                            if (String.valueOf(itemList.get(i).getIid()).equals(itemText.getText())) {
                                itemIs = true;
                            }
                        }

                        if (helpIs == false) {
                            helpText.setForeground(Color.RED);
                            helpText.setText("帮扶人员编号有误！");
                        }

                        if (itemIs == false) {
                            itemText.setForeground(Color.RED);
                            itemText.setText("贫困项目编号有误！");
                        }

                        if (helpIs && itemIs) {
                            String insert = "insert into user_poor(hid, iid, pname, page, psex, pnation, birthplace, reason, health, educated, date) " +
                                    "values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                            JDBCUtils.addPoverty(insert, helpText.getText(), itemText.getText(), nameText.getText(),
                                    ageText.getText(), sexText.getText(), nationText.getText(), birthplaceText.getText(),
                                    reasonText.getText(), healthText.getText(), educatedText.getText(), dateText.getText());

                            dtmPoverty.getDataVector().removeAllElements();

                            String sql = "select * from user_poor";
                            ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sql);

                            String[] title = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                            dtmPoverty.setColumnIdentifiers(title);

                            for (int i = 0; i < list.size(); i++) {
                                dtmPoverty.addRow(new Object[]{list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                                        list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                                        list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
                            }

                            dispose();
                        }
                    }

                    if (helpText.getText().equals("")) {
                        helpText.setForeground(Color.RED);
                        helpText.setText("此框不能为空！");
                    }

                    if (itemText.getText().equals("")) {
                        itemText.setForeground(Color.RED);
                        itemText.setText("此框不能为空！");
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (ageText.getText().equals("")) {
                        ageText.setForeground(Color.RED);
                        ageText.setText("此框不能为空！");
                    }

                    if (sexText.getText().equals("")) {
                        sexText.setForeground(Color.RED);
                        sexText.setText("此框不能为空！");
                    }

                    if (nationText.getText().equals("")) {
                        nationText.setForeground(Color.RED);
                        nationText.setText("此框不能为空！");
                    }

                    if (birthplaceText.getText().equals("")) {
                        birthplaceText.setForeground(Color.RED);
                        birthplaceText.setText("此框不能为空！");
                    }

                    if (reasonText.getText().equals("")) {
                        reasonText.setForeground(Color.RED);
                        reasonText.setText("此框不能为空！");
                    }

                    if (healthText.getText().equals("")) {
                        healthText.setForeground(Color.RED);
                        healthText.setText("此框不能为空！");
                    }

                    if (educatedText.getText().equals("")) {
                        educatedText.setForeground(Color.RED);
                        educatedText.setText("此框不能为空！");
                    }

                    if (dateText.getText().equals("")) {
                        dateText.setForeground(Color.RED);
                        dateText.setText("此框不能为空！");
                    }

                }
            });

            helpText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    helpText.setText("");
                    helpText.setForeground(Color.BLACK);
                }
            });

            itemText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    itemText.setText("");
                    itemText.setForeground(Color.BLACK);
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            ageText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ageText.setText("");
                    ageText.setForeground(Color.BLACK);
                }
            });

            sexText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    sexText.setText("");
                    sexText.setForeground(Color.BLACK);
                }
            });

            nationText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nationText.setText("");
                    nationText.setForeground(Color.BLACK);
                }
            });

            birthplaceText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    birthplaceText.setText("");
                    birthplaceText.setForeground(Color.BLACK);
                }
            });

            reasonText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    reasonText.setText("");
                    reasonText.setForeground(Color.BLACK);
                }
            });

            healthText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    healthText.setText("");
                    healthText.setForeground(Color.BLACK);
                }
            });

            educatedText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    educatedText.setText("");
                    educatedText.setForeground(Color.BLACK);
                }
            });

            dateText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    dateText.setText("");
                    dateText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class addHelpDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(5, 1, 20, 20));
        JPanel p2 = new JPanel(new GridLayout(5, 1, 20, 20));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("填写信息");

        JLabel name = new JLabel("姓名：");
        JLabel age = new JLabel("年龄：");
        JLabel sex = new JLabel("性别：");
        JLabel nation = new JLabel("民族：");
        JLabel address = new JLabel("地址：");

        JTextField nameText = new JTextField(16);
        JTextField ageText = new JTextField(16);
        JTextField sexText = new JTextField(16);
        JTextField nationText = new JTextField(16);
        JTextField addressText = new JTextField(16);

        JButton addButton = new JButton("添加");

        public void init() {
            listen();

            title.setFont(new Font("楷体", Font.BOLD, 30));

            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            age.setFont(new Font("微软雅黑", Font.BOLD, 16));
            sex.setFont(new Font("微软雅黑", Font.BOLD, 16));
            nation.setFont(new Font("微软雅黑", Font.BOLD, 16));
            address.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            ageText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            sexText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            nationText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            addressText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            addButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

            p.add(title);

            p1.add(name);
            p1.add(age);
            p1.add(sex);
            p1.add(nation);
            p1.add(address);

            p2.add(nameText);
            p2.add(ageText);
            p2.add(sexText);
            p2.add(nationText);
            p2.add(addressText);

            p3.add(addButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(300, 350);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            addButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!nameText.getText().equals("") && !ageText.getText().equals("") &&
                            !sexText.getText().equals("") && !nationText.getText().equals("") &&
                            !addressText.getText().equals("")) {

                        String insert = "insert into user_helper(hname, hage, hsex, hnation, address) " +
                                "values(?, ?, ?, ?, ?)";
                        JDBCUtils.addHelp(insert, nameText.getText(), ageText.getText(), sexText.getText(),
                                nationText.getText(), addressText.getText());

                        String sql = "select * from user_helper";
                        ArrayList<Help> list = JDBCUtils.getHelpAllInfo(sql);

                        dtmHelp.getDataVector().removeAllElements();

                        String[] title = new String[]{"帮扶人员编号", "姓名", "年龄", "性别", "民族", "地址"};
                        dtmHelp.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtmHelp.addRow(new Object[]{list.get(i).getHid(), list.get(i).getHname(), list.get(i).getHage(),
                                    list.get(i).getHsex(), list.get(i).getHnation(), list.get(i).getAddress(),});
                        }

                        dispose();
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (ageText.getText().equals("")) {
                        ageText.setForeground(Color.RED);
                        ageText.setText("此框不能为空！");
                    }

                    if (sexText.getText().equals("")) {
                        sexText.setForeground(Color.RED);
                        sexText.setText("此框不能为空！");
                    }

                    if (nationText.getText().equals("")) {
                        nationText.setForeground(Color.RED);
                        nationText.setText("此框不能为空！");
                    }

                    if (addressText.getText().equals("")) {
                        addressText.setForeground(Color.RED);
                        addressText.setText("此框不能为空！");
                    }
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            ageText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    ageText.setText("");
                    ageText.setForeground(Color.BLACK);
                }
            });

            sexText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    sexText.setText("");
                    sexText.setForeground(Color.BLACK);
                }
            });

            nationText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nationText.setText("");
                    nationText.setForeground(Color.BLACK);
                }
            });

            addressText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    addressText.setText("");
                    addressText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class addItemDialog extends JDialog {
        JPanel p = new JPanel();
        JPanel p1 = new JPanel(new GridLayout(2, 1, 25, 25));
        JPanel p2 = new JPanel(new GridLayout(2, 1, 25, 25));
        JPanel p3 = new JPanel();

        JLabel title = new JLabel("填写信息");

        JLabel name = new JLabel("项目名称：");
        JLabel iClass = new JLabel("项目类型：");

        JTextField nameText = new JTextField(16);
        JTextField iClassText = new JTextField(16);

        JButton addButton = new JButton("添加");

        public void init() {
            listen();

            title.setFont(new Font("楷体", Font.BOLD, 30));

            name.setFont(new Font("微软雅黑", Font.BOLD, 16));
            iClass.setFont(new Font("微软雅黑", Font.BOLD, 16));

            nameText.setFont(new Font("微软雅黑", Font.BOLD, 14));
            iClassText.setFont(new Font("微软雅黑", Font.BOLD, 14));

            addButton.setFont(new Font("微软雅黑", Font.BOLD, 16));

            p.add(title);

            p1.add(name);
            p1.add(iClass);

            p2.add(nameText);
            p2.add(iClassText);

            p3.add(addButton);

            add(p, BorderLayout.NORTH);
            add(p1, BorderLayout.WEST);
            add(p2, BorderLayout.CENTER);
            add(p3, BorderLayout.SOUTH);

            setVisible(true);
            setSize(300, 220);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            addButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!nameText.getText().equals("") && !iClassText.getText().equals("")) {

                        String insert = "insert into items(iname, iclass) values(?, ?)";
                        JDBCUtils.addItem(insert, nameText.getText(), iClassText.getText());

                        dtmItem.getDataVector().removeAllElements();

                        String sql = "select * from items";
                        ArrayList<Item> list = JDBCUtils.getItemAllInfo(sql);

                        String[] title = new String[]{"项目编号", "项目名称", "项目类型"};
                        dtmItem.setColumnIdentifiers(title);

                        for (int i = 0; i < list.size(); i++) {
                            dtmItem.addRow(new Object[]{list.get(i).getIid(), list.get(i).getIname(), list.get(i).getIclass()});
                        }

                        dispose();
                    }

                    if (nameText.getText().equals("")) {
                        nameText.setForeground(Color.RED);
                        nameText.setText("此框不能为空！");
                    }

                    if (iClassText.getText().equals("")) {
                        iClassText.setForeground(Color.RED);
                        iClassText.setText("此框不能为空！");
                    }
                }
            });

            nameText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    nameText.setText("");
                    nameText.setForeground(Color.BLACK);
                }
            });

            iClassText.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    iClassText.setText("");
                    iClassText.setForeground(Color.BLACK);
                }
            });
        }
    }

    class DeletePovertyDialog extends JDialog {
        JLabel pidLabel = new JLabel("请输入你要删除的贫困人员编号：");
        JTextField pidText = new JTextField(10);
        JButton pidButton = new JButton("确定");

        public void init() {
            listen();

            pidLabel.setFont(new Font("微软雅黑", 1, 16));
            pidText.setFont(new Font("微软雅黑", 1, 14));
            pidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(pidLabel);
            add(pidText);
            add(pidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getPoverty = "select * from user_poor";
            ArrayList<Poverty> povertyList = JDBCUtils.getPovertyAllInfo(getPoverty);

            pidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < povertyList.size(); i++) {
                        if (String.valueOf(povertyList.get(i).getPid()).equals(pidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new PovertyNotExistHint().init();
                    } else {
                        dispose();

                        new ConfirmDeletePovertyHint(Integer.valueOf(pidText.getText())).init();
                    }
                }
            });
        }
    }

    class ConfirmDeletePovertyHint extends JDialog {
        JLabel hint = new JLabel("你确定要删除该贫困人员吗？");
        JButton comfirm = new JButton("确认");
        JButton cancel = new JButton("取消");
        Integer pid;

        public ConfirmDeletePovertyHint(Integer pid) {
            this.pid = pid;
        }

        public void init() {
            comfirm.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String delete = "delete from user_poor where pid = ?";
                    JDBCUtils.deletePoverty(delete, pid);

                    dtmPoverty.getDataVector().removeAllElements();

                    String sql = "select * from user_poor";
                    ArrayList<Poverty> list = JDBCUtils.getPovertyAllInfo(sql);

                    String[] title = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                    dtmPoverty.setColumnIdentifiers(title);

                    for (int i = 0; i < list.size(); i++) {
                        dtmPoverty.addRow(new Object[]{list.get(i).getPid(), list.get(i).getHid(), list.get(i).getIid(), list.get(i).getPname(),
                                list.get(i).getPage(), list.get(i).getPsex(), list.get(i).getPnation(), list.get(i).getBirthplace(),
                                list.get(i).getReason(), list.get(i).getHealth(), list.get(i).getEducated(), list.get(i).getDate()});
                    }

                    dispose();
                }
            });

            cancel.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            });

            hint.setForeground(Color.RED);
            hint.setFont(new Font("微软雅黑", 1, 18));
            comfirm.setFont(new Font("微软雅黑", 1, 16));
            cancel.setFont(new Font("微软雅黑", 1, 16));

            setLayout(new FlowLayout());

            add(hint);
            add(comfirm);
            add(cancel);

            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setSize(300, 130);
        }
    }

    class DeleteHelpDialog extends JDialog {
        JLabel hidLabel = new JLabel("请输入你要删除的帮扶人员编号：");
        JTextField hidText = new JTextField(10);
        JButton hidButton = new JButton("确定");

        public void init() {
            listen();

            hidLabel.setFont(new Font("微软雅黑", 1, 16));
            hidText.setFont(new Font("微软雅黑", 1, 14));
            hidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(hidLabel);
            add(hidText);
            add(hidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getHelp = "select * from user_helper";
            ArrayList<Help> helpList = JDBCUtils.getHelpAllInfo(getHelp);

            hidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < helpList.size(); i++) {
                        if (String.valueOf(helpList.get(i).getHid()).equals(hidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new HelpNotExistHint().init();
                    } else {
                        dispose();

                        new ConfirmDeleteHelpHint(Integer.valueOf(hidText.getText())).init();
                    }
                }
            });
        }
    }

    class ConfirmDeleteHelpHint extends JDialog {
        JLabel hint = new JLabel("你确定要删除该帮扶人员吗？");
        JButton comfirm = new JButton("确认");
        JButton cancel = new JButton("取消");
        Integer hid;

        public ConfirmDeleteHelpHint(Integer hid) {
            this.hid = hid;
        }

        public void init() {
            comfirm.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String delete = "delete from user_helper where hid = ?";
                    JDBCUtils.deletePoverty(delete, hid);

                    dtmHelp.getDataVector().removeAllElements();

                    String sql = "select * from user_helper";
                    ArrayList<Help> list = JDBCUtils.getHelpAllInfo(sql);

                    String[] title = new String[]{"帮扶人员编号", "姓名", "年龄", "性别", "民族", "地址"};
                    dtmHelp.setColumnIdentifiers(title);

                    for (int i = 0; i < list.size(); i++) {
                        dtmHelp.addRow(new Object[]{list.get(i).getHid(), list.get(i).getHname(), list.get(i).getHage(),
                                list.get(i).getHsex(), list.get(i).getHnation(), list.get(i).getAddress()});
                    }

                    dtmPoverty.getDataVector().removeAllElements();

                    String povertySql = "select * from user_poor";
                    ArrayList<Poverty> povertyList = JDBCUtils.getPovertyAllInfo(povertySql);

                    String[] povertyTitle = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                    dtmPoverty.setColumnIdentifiers(povertyTitle);

                    for (int i = 0; i < povertyList.size(); i++) {
                        dtmPoverty.addRow(new Object[]{povertyList.get(i).getPid(), povertyList.get(i).getHid(), povertyList.get(i).getIid(), povertyList.get(i).getPname(),
                                povertyList.get(i).getPage(), povertyList.get(i).getPsex(), povertyList.get(i).getPnation(), povertyList.get(i).getBirthplace(),
                                povertyList.get(i).getReason(), povertyList.get(i).getHealth(), povertyList.get(i).getEducated(), povertyList.get(i).getDate()});
                    }

                    dispose();
                }
            });

            cancel.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            });

            hint.setForeground(Color.RED);
            hint.setFont(new Font("微软雅黑", 1, 18));
            comfirm.setFont(new Font("微软雅黑", 1, 16));
            cancel.setFont(new Font("微软雅黑", 1, 16));

            setLayout(new FlowLayout());

            add(hint);
            add(comfirm);
            add(cancel);

            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setSize(300, 130);
        }
    }

    class DeleteItemDialog extends JDialog {
        JLabel iidLabel = new JLabel("请输入你要删除的贫困项目编号：");
        JTextField iidText = new JTextField(10);
        JButton iidButton = new JButton("确定");

        public void init() {
            listen();

            iidLabel.setFont(new Font("微软雅黑", 1, 16));
            iidText.setFont(new Font("微软雅黑", 1, 14));
            iidButton.setFont(new Font("微软雅黑", 1, 14));

            setLayout(new FlowLayout());
            add(iidLabel);
            add(iidText);
            add(iidButton);

            setVisible(true);
            setSize(500, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }

        public void listen() {
            String getItem = "select * from items";
            ArrayList<Item> itemList = JDBCUtils.getItemAllInfo(getItem);

            iidButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    boolean povertyIs = false;
                    for (int i = 0; i < itemList.size(); i++) {
                        if (String.valueOf(itemList.get(i).getIid()).equals(iidText.getText())) {
                            povertyIs = true;
                        }
                    }

                    if (povertyIs == false) {
                        new ItemNotExistHint().init();
                    } else {
                        dispose();

                        new ConfirmDeleteItemHint(Integer.valueOf(iidText.getText())).init();
                    }
                }
            });
        }
    }

    class ConfirmDeleteItemHint extends JDialog {
        JLabel hint = new JLabel("你确定要删除该贫困项目吗？");
        JButton comfirm = new JButton("确认");
        JButton cancel = new JButton("取消");
        Integer iid;

        public ConfirmDeleteItemHint(Integer iid) {
            this.iid = iid;
        }

        public void init() {
            comfirm.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String delete = "delete from items where iid = ?";
                    JDBCUtils.deletePoverty(delete, iid);

                    dtmItem.getDataVector().removeAllElements();

                    String sql = "select * from items";
                    ArrayList<Item> list = JDBCUtils.getItemAllInfo(sql);

                    String[] title = new String[]{"项目编号", "项目名称", "项目类型"};
                    dtmItem.setColumnIdentifiers(title);

                    for (int i = 0; i < list.size(); i++) {
                        dtmItem.addRow(new Object[]{list.get(i).getIid(), list.get(i).getIname(), list.get(i).getIclass()});
                    }

                    dtmPoverty.getDataVector().removeAllElements();

                    String povertySql = "select * from user_poor";
                    ArrayList<Poverty> povertyList = JDBCUtils.getPovertyAllInfo(povertySql);

                    String[] povertyTitle = new String[]{"贫困人员编号", "帮扶人员编号", "项目编号", "姓名", "年龄", "性别", "民族", "籍贯", "贫困原因", "身体状况", "受教育程度", "登记时间"};
                    dtmPoverty.setColumnIdentifiers(povertyTitle);

                    for (int i = 0; i < povertyList.size(); i++) {
                        dtmPoverty.addRow(new Object[]{povertyList.get(i).getPid(), povertyList.get(i).getHid(), povertyList.get(i).getIid(), povertyList.get(i).getPname(),
                                povertyList.get(i).getPage(), povertyList.get(i).getPsex(), povertyList.get(i).getPnation(), povertyList.get(i).getBirthplace(),
                                povertyList.get(i).getReason(), povertyList.get(i).getHealth(), povertyList.get(i).getEducated(), povertyList.get(i).getDate()});
                    }

                    dispose();
                }
            });

            cancel.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dispose();
                }
            });

            hint.setForeground(Color.RED);
            hint.setFont(new Font("微软雅黑", 1, 18));
            comfirm.setFont(new Font("微软雅黑", 1, 16));
            cancel.setFont(new Font("微软雅黑", 1, 16));

            setLayout(new FlowLayout());

            add(hint);
            add(comfirm);
            add(cancel);

            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setSize(300, 130);
        }
    }

    class PublicTableShowInfo extends JDialog {
        public void init() {
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    dispose();
                }
            });

            head.setFont(new Font("微软雅黑", 1, 15));
            head.setReorderingAllowed(false);

            table.setFont(new Font("微软雅黑", 1, 13));
            table.setEnabled(false);
            table.setRowHeight(20);

            add(scroll);

            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
    }
}
